package com.lsw.jgyf.ui.fragment;


import android.text.TextUtils;

import com.lsw.dialog.DialogProgress;
import com.lsw.jgyf.httpapi.HttpApi;
import com.lsw.jgyf.inject.Constants;
import com.lsw.jgyf.ui.base.presenter.BasePresenter;
import com.lsw.util.LogUtils;
import com.lsw.util.ToastUtil;

import javax.inject.Inject;

import io.reactivex.disposables.Disposable;

/**
 * Created by lsw on 2017/12/7.
 */

public class HomeFragment1Presenter extends BasePresenter<HomeFragment1Contract.View> implements HomeFragment1Contract.Presenter {
    @Inject
    HttpApi httpApi;

    @Inject
    public HomeFragment1Presenter() {
    }

    @Override
    public void getData(String page, String name) {
        DialogProgress progress = new DialogProgress(mContext);
        progress.show();
        Disposable disposable = httpApi
                .getindex(name, page)
                .subscribe(baseBean -> {
                    mView.RefreshSucceed();
                    progress.dismiss();
                    if (baseBean.getStatus() == Constants.CODE_SUCESS) {
                        if (TextUtils.equals("1", page)) {
                            mView.setBanner(baseBean.getData().getBanner_list().getData());
                        }
                        if (baseBean.getData().getPhone_list().getData().size() < Constants.PAGE_DEFAULT_COUNT) {
                            mView.setData(baseBean.getData().getPhone_list().getData(), false);
                        } else {
                            mView.setData(baseBean.getData().getPhone_list().getData(), true);
                        }
                    } else {
                        ToastUtil.showToast(mContext, baseBean.getMessage());
                    }
                }, throwable -> {
                    mView.RefreshFail();
                    progress.dismiss();
                    LogUtils.e("TAG_Enroll", throwable.getMessage());
                });
        mCompositeDisposable.add(disposable);
    }

    @Override
    public void getBanner() {
//        DialogProgress progress = new DialogProgress(mContext);
//        progress.show();
//        Disposable disposable = httpApi
//                .getBanner()
//                .subscribe(baseBean -> {
//                    mView.RefreshSucceed();
//                    progress.dismiss();
//                    if (baseBean.getStatus() == Constants.CODE_SUCESS) {
//                        mView.setBanner(baseBean.getData().getData());
//                    } else {
//                        ToastUtil.showToast(mContext, baseBean.getMessage());
//                    }
//                }, throwable -> {
//                    mView.RefreshFail();
//                    progress.dismiss();
//                    LogUtils.e("TAG_Enroll", throwable.getMessage());
//                });
//        mCompositeDisposable.add(disposable);
    }
}
